package n.d.l.svn.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@WebFilter(filterName="staticFilter", urlPatterns="/*")
@Component
public class StaticFilter implements Filter {

	private static final Logger log = LoggerFactory.getLogger(StaticFilter.class);
	@Value("${server.servlet-path}")
	private String servletPath;
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		log.debug("[staticFilter] 拦截器启动");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		request.setAttribute("servletPath", servletPath);
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		log.debug("[staticFilter] 拦截器销毁");
	}

}
